/**
 *
 *  copyright: maximus zhang,
 *  License: MIT-LICENSE,
 *  contact: maximus.zhang(a)gmail.com,
 *  update: svn://svnhost.cn/jsease
 *
 */
String.prototype.toInt = function(){
    return isNaN(this) ? NaN : parseInt(this, 10);
};
String.prototype.trim = function(){
    return this.replace(/(^\s+)|\s+$/g, "");
};
String.prototype.left = function(n){
    return this.substr(0, n);
};
String.prototype.right = function(n){
    return this.substr(this.length-n);
};
String.prototype.isFigure = function(){
    return(this.length!==0 && !/\D/.test(this));
};
String.prototype.isGuid = function(){
    if ( this.length!=36 && this.length!=38 ) {
        return false;
    }
    if ( (this.length==38)
        && ((this.left(1)=="{" && this.right(1)!="}")
            || (this.left(1)=="(" && this.right(1)!=")")
            || (this.left(1)!="{" && this.right(1)=="}")
            || (this.left(1)!="(" && this.right(1)==")")
            )
        ) {
        return false;
    }
    return /^[{|\(]?[0-9a-f]{8}[-]?([0-9a-f]{4}[-]?){3}[0-9a-f]{12}[\)|}]?$/i.test(this);
};
function isId(iD){
    if ( iD.length != 15 && iD.length != 18 ) {
        return false;/* "身份证号共有 15位或18位"; */
    }
    var Ai = iD.length==18 ? iD.substring(0,17) : iD.slice(0,6)+"19"+iD.slice(6,16);
    if (!/^\d+$/.test(Ai)) {
        return false;/* "身份证除最后一位外，必须为数字！" */
    }
    var X18 = [1,0,"X",9,8,7,6,5,4,3,2];
    var Wi = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
    var Checker = [1,9,8,7,6,5,4,3,2,1,1];
    var yyyy=Ai.slice(6,10);
    var mm=Ai.slice(10,12)-1;
    var dd=Ai.slice(12,14);
    var d=new Date(yyyy,mm,dd);
    var year=d.getFullYear();
    var mon=d.getMonth();
    var day=d.getDate();
    var now=new Date();
    if (year!=yyyy || mon!=mm || day!=dd || d>now || now.getFullYear()-year>140) {
        return false;/* "身份证输入错误！"; */
    }
    for (var i=0,ret=0;i<17;i++) {
        ret+=Ai.charAt(i)*Wi[i];
    }
    Ai += X18[ret %=11];
    return iD.length == 18 && iD.toUpperCase() != Ai ? false/* "身份证输入错误！" */ : iD.toUpperCase();
}

/**
 * jsonQs parse String like query string to json object.
 * eg. "name=maximus&file=hc.js" will be parsed to {name:'maximus',file:'hc.js'}.
 */
String.prototype.jsonQs = function(s){
    var a = this.match(/([^&]*?)\=([^&]*)/g),
        o = {};
    if ( !a ) {
        return o;
    }

    for ( var z=0, L=a.length; z<L; z++ ) {
        var p = a[z].split('='),
            k = duc(p[0]).trim(),
            v = duc(p[1]);

        if(/%5B%5D$|\[\]$/i.test(k)) {
            k = k.replace(/%5B%5D$|\[\]$/i,'');
            if ( o.hasOwnProperty(k) ) {
                o[k].push(v);
            } else {
                o[k] = [v];
            }
        } else if ( s && o.hasOwnProperty(k)) {
            if ( !isArray(o[k]) ) {
                o[k] = [o[k]];
            }
            o[k].push(v);
        } else {
            o[k] = v;
        }
    }
return o;
};
/**
 * function jsonCss parse code String like css style to json object.
 * one different is those elements' name that end up with '[]' will be parsed
 * to Array object(s).
 * eg. "font[]:宋体;font[]:Arial;" will be parsed to {font:["宋体","Arial"]}.
 * jsonCss 函数转换 如css格式的字符串成为 json对象。
 * 区别一点在于其中对以[]结束的元素名转换为数组。
 * 如："font[]:宋体;font[]:Arial;" 将被转换为：{font:["宋体","Arial"]}.
 */
String.prototype.jsonCss = function(){
    var o = {},
        a = this.replace(/^\;|\f|\n|\r|\t|\v|\;$/g,'')
                .replace(/\;{2,}/g,';').split(';');

    for ( var i=0, L=a.length; i<L; i++ ) {
        var p = a[i].split(':');
        if ( p.length==2 ) {
            var k = duc(p[0]).trim(),
                v = uesc(p[1]).trim();

            if ( /%5B%5D$|\[\]$/i.test(k) ) {
                k = k.replace(/%5B%5D$|\[\]$/i,'');
                if ( o.hasOwnProperty(k) ) {
                    if ( !isArray(o[k]) ) {
                        o[k] = [o[k]];
                    }
                    o[k].push(v);
                } else {
                    o[k] = [v];
                }
            } else {
                o[k] = v;
            }
        }
    }
return o;
};

Number.prototype.int10 = function(){
    return parseInt(this, 10);
};
Number.prototype.floor = function(){
    return Math.floor(this);
};
Number.prototype.ceil = function(){
    return Math.ceil(this);
};
Number.prototype.round = function(x){
    if (isNaN(x)) {
        x=0;
    }
    return Math.round(this*Math.pow(10,x))/Math.pow(10,x);
};

String.prototype.round = function(x){
    if (isNaN(this)) {
        return null;
    }
    return (this*1.0).round(x);
};

Date.prototype.add = function(T, n){
    var FY = this.getFullYear(),
        Mo = this.getMonth(),
        D = this.getDate(),
        H = this.getHours(),
        Mi = this.getMinutes(),
        S = this.getSeconds();

    switch (T.toUpperCase()) {
        case "YY": case "YYYY": case "Y":
            FY += n;
            break;
        case "MM":
            Mo += n;
            break;
        case "DD": case "D":
            D += n;
            break;
        case "H":
            H += n;
            break;
        case "M":
            Mi += n;
            break;
        case "S":
            S += n;
            break;
        case "W": case "WW":
            D += n*7;
            break;
        default:
            return this;
    }

return new Date(FY, Mo, D, H, Mi, S);
};

/**
 * 函数 isArray 判断给定参数 a 是否为 数组类型
 */
function isArray(a){
    if ( !a ) {
        return false;
    }
    return (typeof a!="undefined" ? a.constructor==Array
        : typeof a.length!="undefined");
}

/**
 * isUnique 判断数组a是否没有重复值。可选参数[s]为真时忽略对字符串值的大小写判断
 */
function isUnique(a, s){
    if ( !isArray( a ) ) {
        return true;
    }
    for (var x = 0, L = a.length; x<L; x++) {
        for ( var z = x+1; z<L; z++ ) {
            if ( typeof(a[x])=="string" || typeof(a[z])=="string" ) {
                if ( s && a[x].toUpperCase()==a[z].toUpperCase() ) {
                    return false;
                } else {
                    if ( a[x]==a[z] ) {
                        return false;
                    }
                }
            }
        }
    }
return true;
}

/**
 * 函数 inArray 判断给定值是否在给定的数组内。
 * 参数 ( v, a [, s] )
 * v: 给定值，字符串或数值类型；
 * a: 数组类型；
 * s: 可选，为真时严格类型判断
 */
function inArray(v,a,s){
    if ( !isArray(a) || a.length===0 ) {
        return false;
    }

    var eq = (function(){
            if(s)return function(x,y){return x===y;};
            else return function(x,y){return x==y;};
        })();

    if (typeof(v)=='string' || typeof(v)=='number') {
        for (var z=0, L=a.length; z<L; z++) {
            if ( eq(a[z],v) ) {
                return true;
            }
        }
    }
return false;
}

function now(F){
    var _ = new Date();
    if ( 'number'==typeof F ) {
        switch ( F ) {
            case 1:
                return _.toUTCString();
                break;
            case 2:
                return _.valueOf();
                break;
            case 3:
                return _.valueOf().toString();
                break;
            default:
                return _;
                break;
        }
    }
return _;
}

/**
 * 函数 ext 对 json 对象进行“扩展”。
 * 即，将新对象 O 的属性及其值对旧对象 o 进行扩展，
 * 使原对象 o 在原来的基础上有对象 O 的属性及值。
 * O 的属性会覆盖 o 的属性。
 * 参数 s 为真时仅限对 o 原有属性进行扩展。不增加新属性。
 * 即，只对 o 的原有属性赋新值。
 */
function ext(o, O, s){
    if ( 'object'!=typeof(o) || 'object'!=typeof(O) || !o || !O ) {
        return o;
    }
    if ( s ) {
        for (var z in o) {
            if ( hop(O,z) ) {
                o[z] = O[z];
            }
        }
    } else {
        for (var z in O) {
            o[z] = O[z];
        }
    }
return o;
}

function ext$(_o, O, s){
    if ( 'object'!=typeof(_o) || 'object'!=typeof(O) || !_o || !O ) {
        return _o;
    }

    var o = ext({}, _o);

    if ( s ) {
        return ext(o, O);
    }

    for (var x in o) {
        if ( O.hasOwnProperty(x) && typeof(o[x])==typeof(O[x]) ) {
            if ( O[x] && o[x] && 'object'==typeof(o[x]) ) {
                o[x] = arguments.callee(o[x], O[x]);
            } else {
                o[x] = O[x];
            }
        }
    }

return o;
}

function esc(z){if(!z)return z;return escape(z +'');}
function uesc(z){if(!z)return z;return unescape(z +'');}
function euc(z){if(!z)return z;return encodeURIComponent(z +'');}
function duc(z){if(!z)return z;return decodeURIComponent(z +'');}

/*
 * function uriJson parse a json Object to uri-ify string.
 * eg. {name:"max", value:"2008"} will be parsed to "name=max&value=2008" .
 *
 * uriJson 函数转换 json对象 成为如地址栏用的字符串。
 * 如：{name:"max", value:"2008"} 将被转换为："name=max&value=2008" .
 *
 * **可用于在ajax中将对象转换为字符串并发送给服务器**
 */
function uriJson(o,isphp){
    if ( !o||'object'!==typeof(o) ) {
        return;
    }

    var a=[],
        A=arguments;

    for ( var z in o ) {
        if (null===o[z]) {
            a.push(euc(z) +'=');
            continue;
        }

        if ( isArray(o[z]) ) {
            for ( var x=0, L=o[z].length; x<L; x++ ) {
                if (typeof(o[z][x])=='object') {
                    a.push(A.callee(o[z][x]));
                } else {
                    a.push(euc(z +(!isphp?'':'[]')) +'='+ euc(o[z][x]));
                }
            }
        } else if (o[z] && typeof(o[z])=='object') {
            a.push(A.callee(o[z]));
        } else if (typeof(o[z])=='function') {
            continue;
        } else {
            a.push(euc(z) +'='+ euc(o[z]));
        }
    }
return a.join('&').replace(/%20/g, '+');
}

function kov(o, v) {
    if ( !o || typeof o!='object' ) {
        return '';
    }

    for ( var k in o ) {
        if ( o[k]==v ) {
            return k;
        }
    }

return '';
}

function osort$(O, k) {
    var o = {};
    if ( !O || !k ) {
        return o;
    }
    for ( var x in O ) {
        if ( hop(O[x], k) ) {
            var v = O[x][k];
            if ( v && typeof v=='string' ) {
                if ( hop(o, v) ) {
                    if ( !isArray(o[v]) ) {
                        o[v] = [o[v]];
                    }
                    o[v].push( O[x] );
                } else {
                    o[v] = O[x];
                }
            }
        }
    }
return o;
}

/*
 *函数strJson 将 json 对象转换为json字符串。
 *
 */
function strJson(O){
    if ( !O ) {
        return '';
    }

    var a = [],
        A = arguments;

    if (typeof(O)=='object') {
        if (isArray(O)) {
            for (var x=0, L=O.length; x<L; x++) {
                if (O[x] && typeof(O[x])=='object') {
                    a.push(A.callee(O[x]));
                } else {
                    var q = O[x]=='' ? '"' : isNaN(O[x]) ? '"' : '';
                    a.push(q + O[x] + q);
                }
            }
            return '['+ a.join(',') +']';
        } else {
            for (var z in O) {
                if (O[z] && typeof(O[z])=='object') {
                    a.push('"'+ z +'":'+ A.callee(O[z]));
                } else if ( O[z]===null ) {
                    a.push('"'+ z +'":null');
                } else if ( typeof O[z]=='undefined' ) {
                    a.push('"'+ z +'":undefined');
                } else if ( typeof O[z]=='boolean' ) {
                    a.push('"'+ z +'":'+ O[z]);
                } else if ( typeof O[z]=='function' ) {
                    continue;
                } else {
                    var q=O[z]=='' ? '"' : isNaN(O[z]) ? '"' : '';
                    a.push('"'+ z +'":'+ q + O[z] + q);
                }
            }
            return '{'+ a.join(',') +'}';
        }
    }
}

function hop(o, p){
    return typeof o=='object' && o && typeof p=='string' && o.hasOwnProperty(p);
}

/**
 * 函数 p 检查 对象 o 是否有属性 p
 */
function p(o, p, _p){
    /* check if o has property p. if sub _p is given, check if o.p has property _p */
    if ( !_p ) {
        return hop(o,p) && typeof o[p]=='string' && o[p].length>0;
    } else {
        return hop(o,p) && hop(o[p],_p) && typeof o[p][_p]=='string' && o[p][_p].length>0;
    }
}

function ex(er){if(!er)return;alert(er);return false;}

var me = document,
    _$$ = navigator.userAgent.toLowerCase(),

    $$ = window.$$ = {
        $ : {},
        version : (_$$.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1],
        safari : /webkit/.test(_$$),
        opera : /opera/.test(_$$),
        msie : /msie/.test(_$$) && !/opera/.test(_$$),
        mozilla : /mozilla/.test(_$$) && !/(compatible|webkit)/.test(_$$),
        cookie : window.navigator.cookieEnabled,
        html : me.documentElement,
        head : me.getElementsByTagName('head')[0],
        w : screen.availWidth,
        h : screen.availHeight,
        ty : null,
        by : null,
        pH : null,
        pW : null,
        regx : {
            varname: /^[a-z][a-z0-9]*(\.)?[a-z0-9]+$/i,
            code:/^[a-zA-Z][A-Za-z0-9]*$/,
            email:/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/,
            nz: /^[1-9]\d*$/,
            price:/^([1-9]\d*\.?\d*)$|^(0\.\d*[1-9]\d*)$/,
            pwd:/^[A-Za-z0-9].+$/,
            num: /^\d+$/,
            str: /.+/
            }
    };

/**
 * 函数 def 提供一个 window级 的函数对象定义方法
 * 参数：( str 对象变量名, str 类名, json 实际参数 )
 * 如提供的类存在，将在window级建立一个名称为所提供对象变量名的对象。
 * 并运行该对象的init()方法。
 */
function def(n, cls, arg, ss){
    if ( ss ) {
        if ( !/^[a-z\$_][a-z\$_\d]*$/i.test( n ) ) {
            return alert('IdentifierName "'+ n +'" not valid!\n\n'
            +'The valid identifierName limited here to be:\n'
            +'1. A leading charactor of "[a-z\\$_]"\n'
            +'[2. and following any of "[a-z\\$_\\d]"] (optional)');
        }
    }

    if ( typeof window[cls] != 'function' ) {
        return alert('class "'+ cls +'" not exist!');
    }

    window[n] = $$.$[n] = new window[cls](arg);

    if ( typeof window[n].init == 'function' ) {
        window[n].init();
    }

return window[n];
}

/**
 * 函数 var$ 提供一个 window级 的变量定义方法
 * 参数：( str 变量名, str 变量定义 )
 */
function var$(n, df) {
    window[n] = df;
return window[n];
}

function $(z){
    var o = ( !z || typeof(z) != 'string') ? z : /^&/.test(z)
            ? me.getElementsByName(z.replace(/^&/,'')) : me.getElementById(z);
    if ( o && o.nodeName ) {
        o.attr = function(a,v,f){
            if ( f===1||f===0 ) {
                o.setAttribute(a,v,f);
            return o;
            } else if ( typeof v!='undefined' ) {
                o.setAttribute(a,v);
            return o;
            } else {
                return o.getAttribute(a);
            }
        };

        o.appendTo = function(e){
            var e = e && e.nodeName ? e : me.body;
            e.appendChild(this);
            return o;
        };

        o.empty = function(){
            while ( o.hasChildNodes() ) {
                o.removeChild(o.firstChild);
            }
            return o;
        };

        o.html = function (a) {
            o.innerHTML = a;
        return o;
        };
    }
return o;
}

function geTags(el, tag){
    return el.getElementsByTagName(tag);
}

/**
 * 函数 elm 用于创建 dom 元素，第二个参数为真时为创建 文本dom对象。
 */
function elm(e, t){
    if ( typeof e!='string' ) {
        return false;
    }

    var E = !t ? me.createElement(e) : me.createTextNode(e);

    if ( !t && ( !E || E.nodeName!=e.toUpperCase() ) ) {
        return false;
    }

    if (E.nodeType!==3) {
        E.appendTo = function(O){
            var O = O && O.nodeName ? O : me.body;
            O.appendChild(E);
        return E;
        };

        E.before = function(O){
            var O = O || me.body;
            if ( O==me.body ) {
                O.firstChild ? O.insertBefore(E, O.firstChild) : O.insertBefore(E);
            } else {
                O.parentNode.insertBefore(E,O);
            }
        return E;
        };

        E.after=function(O){
            var O = O || me.body;
            if ( O==me.body ) {
                O.appendChild(E);
            } else {
                O.parentNode.insertBefore(E,O.nextSibling);
            }
        return E;
        };

        E.setClass = E.class$ = function(n){
            if ( typeof n=='string' && isNaN(n) && n.length>0 ) {
                E.className = n;
            }
        return E;
        };

        E.addClass = function(n){
            if ( typeof n=='string' && isNaN(n) && n.length>0 ) {
                if ( E.className.indexOf(n)==-1 ) {
                    E.className += ' '+ n;
                }
            }
        return E;
        };
        E.delClass = function(n){
            if ( typeof n=='string' && isNaN(n) && n.length>0 ) {
                if ( E.className.indexOf(n)!=-1 ) {
                    E.className = E.className.replace(n, '').trim();
                }
            }
        return E;
        };

        E.attr = function(a,v,f){
            if ( f===1||f===0 ) {
                E.setAttribute(a,v,f);
            return E;
            } else if ( typeof v!='undefined' ) {
                E.setAttribute(a,v);
            return E;
            } else {
                return E.getAttribute(a);
            }
        };

        E.empty = function(){
            while ( E.hasChildNodes() ) {
                E.removeChild(E.firstChild);
            }
        return E;
        };

        E.html = function (a) {
            E.innerHTML = a;
        return E;
        };

        E.remove = function () {
        return me.body.removeChild(E.appendTo(me.body));
        };
    }

return E;
}

/**
 * setSelect 选定 值为v 的选择下拉菜单o 的下拉项。
 */
function setSelect(o, v){
    if ( o && o.nodeName=="SELECT" && !o.disabled ) {
        o.selectedIndex = -1;
        if (o.type=="select-one") {
            for ( var z=0, L=o.length; z<L; z++ ) {
                if ( o.options[z].value==v ) {
                    return o.selectedIndex = z;
                }
            }
        } else if ( o.type=="select-multiple" ) {
            if ( !isArray(v) ) {
                return false;
            }

            for ( var z=0, L=o.length; z<L; z++ ) {
                if ( inArray(o.options[z].value,v) ) {
                    o.options[z].selected = true;
                }
            }
        }
    }
}

function setCheckbox(o, v){
    if ( o.length ) {
        for ( var z=0, L=o.length; z<L; z++ ) {
            if ( o[z] && o[z].nodeName=="INPUT" && !o[z].disabled ) {
                switch ( o[z].type ) {
                    case 'radio':
                        if ( o[z].value==v ) {
                            return o[z].checked=true;
                        }
                        break;
                    case 'checkbox':
                        if ( !isArray(v) ) {
                            return false;
                        }

                        if ( inArray(o[z].value,v) ) {
                            o[z].checked = true;
                        } else {
                            o[z].checked = false;
                        }
                        break;
                }
            }
        }
    } else {
        if ( o && o.nodeName=="INPUT" && ( o.type=="radio" || o.type=="checkbox" ) && !o.disabled ) {
            if ( o.value==v ) {
                return o.checked=true;
            } else {
                return o.checked=o.defaultChecked;
            }
        }
    }
}

/**
 * 将json对象的属性及其值设置表单
 */
function setForm(o, f, skip){
    var f = typeof(f)=='string' ? $(f)
            : ( typeof(f)=="object" && f ) ? f
            : ( typeof(f)=="number" ) ? me.forms[f] : f,
        skip = ext({},skip);

    if ( !f || f.nodeName!=="FORM" ) {
        return;
    }

    if (o && typeof o=="object") {
        var an = (typeof(skip.name)=='string') ? skip.name.toLowerCase().split(',')
                : isArray(skip.name) ? skip.name : [],
            ae = (typeof(skip.elem)=='string') ? skip.elem.toUpperCase().split(',')
                : isArray(skip.elem) ? skip.elem : [],
            at = (typeof(skip.type)=='string') ? skip.type.toLowerCase().split(',')
                : isArray(skip.type) ? skip.type : [];
        for (var z in o) {
            if ( !inArray(z,an) && ( f.elements[z] || ( isArray(o[z]) && f.elements[z+'[]'] ) ) ) {
                var el = f.elements[z] ? f.elements[z] : isArray(o[z]) ? f.elements[z+'[]'] : null;

                if ( !el.length && !el.disabled && !inArray(el.nodeName, ae) ) {
                    switch ( el.nodeName ) {
                        case 'INPUT':
                            if ( !inArray(el.type, at) ) {
                                switch ( el.type ) {
                                    case 'text':
                                    case 'hidden':
                                    case 'password':
                                        el.value = o[z];
                                        break;
                                    case 'radio':
                                    case 'checkbox':
                                        setCheckbox(el, o[z]);
                                        break;
                                }
                            }
                            break;
                        case 'TEXTAREA':
                            el.innerHTML = o[z];
                            break;
                    }
                } else if ( el.length && !inArray(el.nodeName,ae) ) {
                    if ( el.nodeName=='SELECT' && !el.disabled ) {
                        setSelect(el, o[z]);
                    } else if ( el[0].nodeName=='INPUT' ) {
                        if ( !inArray(el.type,at) ) {
                            switch ( el[0].type ) {
                                case 'text':
                                case 'hidden':
                                case 'password':
                                    for (var x=0, J=el.length; x<J; x++) {
                                        if ( !el[x].disabled ) {
                                            el[x].value = o[z][x] ? o[z][x] : '';
                                        }
                                    }
                                    break;
                                case 'radio':
                                case 'checkbox':
                                    setCheckbox(el, o[z]);
                                    break;
                            }
                        }
                    }
                }
            }
        }
    }
}

/**
 * 建立 XMLHttpRequest 对象
 * not suport for IE6
 */
function aja$(){/*{method,url,async,xml,data, filedata},{f0~f4,finish,fail}*/
    var A = arguments,
        xhr = new XMLHttpRequest();// window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") :,
        y = ext({method: "post", url: "", async: true, data: null, xml: false, filedata: null}, A[0]);

    if (A.length==0 || !p(y, 'url')) {
        return xhr;
    }

    if ( /^get$/i.test(y.method) ) {
        if (y.data==null || y.data==''){
            ;
        } else {
            y.url += y.url.match(/\?/) ? '&' : '?';
            if ( p(y, 'data') ) {
                y.url += y.data.match(/\?/) ? y.data.split('?')[1] : y.data;
            } else {
                y.url += uriJson(y.data);
            }
        }
        y.data = null;
    } else if ( !/^post$/i.test(y.method) ) {
        y.method="post";
        var z=y.url.jsonQs();

        if ( typeof y.data=='string' && uriJson(z) ) {
            y.data = uriJson(z) +'&'+ y.data;
        } else if ( y.data && typeof y.data=='object' ) {
            y.data = ext(z,y.data);
        }
    }

    xhr.open(y.method, y.url, y.async);
    xhr.setRequestHeader("X-Request-Method", "XMLHttpRequest.aja$");
    if ( y.filedata ) {
        xhr.setRequestHeader("Content-Type", "multipart/form-data");
    } else {
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    }

    if ( A.length==1 ){
        return xhr;
    }

    if(A.length>1){
        var fn = ext({ f0:function(){;}, f1:function(){;}, f2:function(){;},
            f3:function(){;}, f4:function(){;},
            fail:function(){;}, finish:function(){;},
            progress:function(){;}, uprogress:function(){;},
            loadstart:function(){;}, uploadstart:function(){;},
            loadend:function(){;}, uploadend:function(){;}
            }, A[1] );
        try {
            xhr.onprogress = function(e){
                fn.progress(e);
            };
            xhr.upload.onprogress = function(e){
                fn.uprogress(e);
            };
            xhr.onloadstart = function(e){
                fn.loadstart(e);
            };
            xhr.upload.onloadstart = function(e){
                fn.uploadstart(e);
            };
            xhr.onloadend = function(e){
                fn.loadend(e);
            };
            xhr.upload.onloadend = function(e){
                fn.uploadend(e);
            };
        } catch(ex){}
        xhr.onreadystatechange = function(){
            switch ( xhr.readyState ) {
                case 0:
                    fn.f0();
                    break;
                case 1:
                    fn.f1();
                    break;
                case 2:
                    fn.f2();
                    break;
                case 3:
                    fn.f3();
                    break;
                case 4:
                    var r = y.xml ? xhr.responseXML : xhr.responseText;
                    if ( !r ){
                        if (xhr.status != 0){
                            alert(xhr.status +' Error!\n\nPlease check the network connection...');
                        }
                    } else if ( xhr.status==302 ) {
                        top.location.replace(r);
                    } else if ( xhr.status==200 ) {
                        if ( !fn.finish.length ) {
                            try {
                                fn.f4();
                            } catch(ex) {
                                fn.fail(r);
                            }
                        } else {
                            try {
                                fn.finish(r);
                            } catch(ex) {
                                fn.fail(r);
                            }
                        }
                    } else {
                        if ( !fn.fail.length ) {
                            try {
                                fn.f4();
                            } catch(ex) {
                                fn.fail(r);
                            }
                        } else {
                            try {
                                fn.fail(r);
                            } catch(ex) {
                                ex(ex);
                            }
                        }
                    }
                    break;
            }
        };
    }

    try {
        if (y.filedata) {
            xhr.send(y.filedata);
        } else {
            xhr.send((y.data==null || p(y, 'data')) ? y.data : uriJson(y.data));
        }
    } catch(e) {
        throw new Error('XMLHttpSendError');
    }
return xhr;
}

function jsonDom(od, s, oc/* inner use only */) {
    if ( !od || !od.nodeType ) {
        return false;
    }
    var o = {};

    var getAttrs = function(ne) {
        var oa = {};

        if ( ne.nodeType!=1 ) {
            return null;
        }

        var na = ne.attributes;
        for ( var i=0,L=na.length; i<L; i++ ) {
            oa[na[i].nodeName] = na[i].nodeValue;
        }
        if ( L===0 ) {
            oa = null;
        }
    return oa;
    };

    if ( od.nodeType==1 && !oc ) {
        var oo = {};
        oo[od.nodeName] = o;
    }

    var at = getAttrs( od );
    if ( at ) {
        if ( oo && !oc ) {
            oo['@attributes'] = at;
        } else {
            o['@attributes'] = at;
        }
    }

    if ( od.hasChildNodes() ) {
        for ( var i = 0, L = od.childNodes.length; i<L; i++ ) {
        /* c = od.firstChild; c; c = c.nextSibling */
            var c = od.childNodes[i],
                k = c.nodeName;
            switch ( c.nodeType ) {
                case 1:
                    if ( !hop(o, k) ) {
                        o[k] = arguments.callee( c, !!s, 1 );
                    } else {
                        if ( !isArray( o[k] ) ) {
                            o[k] = [o[k]];
                        }
                        o[k].push( arguments.callee( c, !!s, 1 ) );
                    }
                    break;
                case 3:
                    if ( c.nodeValue.match(/[^ \f\n\r\t\v]/) ) {
                        if ( !s || at ) {
                            o[k] = c.nodeValue.trim();
                        } else {
                            o = c.nodeValue.trim();
                        }
                    }
                    break;
                case 4:
                case 8:
                    if ( !s || at ) {
                        o[k] = c.nodeValue.trim();
                    } else {
                        o = c.nodeValue.trim();
                    }
                    break;
            }
        }
    } else {
        if ( at ) {
            if ( oo && !oc ) {
                oo['@attributes'] = at;
            } else {
                o['@attributes'] = at;
            }
        } else {
            o = '';
        }
    }

return oo ? oo : o;
}

function loadXml(url) {
    if ( !url ) {
        return false;
    }

    if ( window.XMLHttpRequest ) {
        var xml=new XMLHttpRequest();
        xml.open("GET", url, false);
        xml.send(null);
    return xml.responseXML;
    } else if ( window.ActiveXObject ) {
        var xml= new ActiveXObject("Microsoft.XMLDOM");
        xml.async=false;
        xml.load(url);
    return xml;
    }
}

function loadJs(url) {
    if ( !url ) {
        return false;
    }

    var head = geTags(me, 'head')[0] || me.body,
        js = elm('script').attr('type', 'text/javascript').attr('src', url )
            .appendTo( head );

return js;
}

/**
 * 函数jsonForm 将表单对象所包含的控件的内容转换成json对象。
 * 参数1 为表单对象或表单对象的id, 表单对象, 或表单索引号；
 * 参数2 为表单对象中要略过的控件，可为“控件name属性”，“控件元素名”，控件type
 */
function jsonForm(f, skip, isphp){
    /* skip={name:'name'|['name'],elem:'elem'|['elem'],type:'type'|['type']} */
    if ( !f ) {
        return;
    }

    var f = typeof(f)=='string' ? $(f)
            : ( typeof(f)=="object" && f ) ? f
            : ( typeof(f)=="number" ) ? me.forms[f] : f,
        skip = ext({},skip),
        o = {};

    if ( f.nodeName!='FORM' ) {
        return f;
    }

    var an = (typeof(skip.name)=='string') ? skip.name.toLowerCase().split(',')
            : isArray(skip.name) ? skip.name : [],
        ae = (typeof(skip.elem)=='string') ? skip.elem.toUpperCase().split(',')
            : isArray(skip.elem) ? skip.elem : [],
        at = (typeof(skip.type)=='string') ? skip.type.toLowerCase().split(',')
            : isArray(skip.type) ? skip.type : [];

    for ( var x=0, L=f.length; x<L; x++ ) {
        if ( !inArray(f[x].nodeName,ae) && !f[x].disabled && f[x].name
            && f[x].name!='' && !inArray(f[x].name.toLowerCase(),an) ) {
            switch ( f[x].nodeName ) {
                case 'INPUT':
                    if ( !inArray(f[x].type,at) ) {
                        switch ( f[x].type ) {
                            case 'text':
                            case 'hidden':
                            case 'password':
                                if ( /%5B%5D$|\[\]$/i.test(f[x].name)||!isphp ) {
                                    var N = f[x].name.replace(/%5B%5D$|\[\]$/i,'');
                                    if ( o.hasOwnProperty(N) ) {
                                        if(!isArray(o[N])){
                                            o[N] = [o[N]];
                                        }
                                        o[N].push(f[x].value);
                                    } else {
                                        o[N] = f[x].value;
                                    }
                                } else {
                                    o[f[x].name] = f[x].value;
                                }
                                break;
                            case 'file':
                                if ( /%5B%5D$|\[\]$/i.test(f[x].name)||!isphp ) {
                                    var N = f[x].name.replace(/%5B%5D$|\[\]$/i,'');
                                    if ( o.hasOwnProperty(N) ) {
                                        if(!isArray(o[N])){
                                            o[N] = [o[N]];
                                        }
                                        o[N].push(f[x].files);
                                    } else {
                                        o[N] = f[x].files;
                                    }
                                } else {
                                    o[f[x].name] = f[x].files;
                                }
                                break;
                            case 'radio':
                            case 'checkbox':
                                if ( f[x].checked ) {
                                    if ( /%5B%5D$|\[\]$/i.test(f[x].name)||!isphp ) {
                                        var N = f[x].name.replace(/%5B%5D$|\[\]$/i,'');
                                        if ( o.hasOwnProperty(N) ) {
                                            if(!isArray(o[N])){
                                                o[N] = [o[N]];
                                            }
                                            o[N].push(f[x].value);
                                    } else {
                                            o[N] = f[x].value;
                                        }
                                    } else {
                                        o[f[x].name] = f[x].value;
                                    }
                                }
                            break;
                        }
                    }
                    break;
                case 'TEXTAREA':
                    if ( /%5B%5D$|\[\]$/i.test(f[x].name)||!isphp ) {
                        o[f[x].name.replace(/%5B%5D$|\[\]$/i,'')] = [f[x].value];
                    } else {
                        o[f[x].name] = f[x].value;
                    }
                    break;
                case 'SELECT':
                    for (var z=0, J=f[x].length; z<J; z++) {
                        var Oz = f[x].options[z];
                        if ( Oz.selected ) {
                            if ( /%5B%5D$|\[\]$/i.test(f[x].name)||!isphp ) {
                                var N = f[x].name.replace(/%5B%5D$|\[\]$/i,'');
                                if ( o.hasOwnProperty(N) ) {
                                    if(!isArray(o[N])){
                                        o[N] = [o[N]];
                                    }
                                    o[N].push(Oz.value);
                                } else {
                                    o[N]=Oz.value;
                                }
                            } else {
                                o[f[x].name]=Oz.value;
                            }
                        }
                    }
                    break;
            }
        }
    }
return o;
}
function formData(f, skip) {
    /* skip={name:'name'|['name'],elem:'elem'|['elem'],type:'type'|['type']} */
    if ( !f ) {
        return;
    }

    var f = typeof(f)=='string' ? $(f)
            : ( typeof(f)=="object" && f ) ? f
            : ( typeof(f)=="number" ) ? me.forms[f] : f,
        skip = ext({},skip);
    try{
        var o = new FormData();
    } catch(e) {
        alert('your browser does not support HTML5!');
        return null;
    }

    if ( f.nodeName!='FORM' ) {
        return f;
    }

    var an = (typeof(skip.name)=='string') ? skip.name.toLowerCase().split(',')
            : isArray(skip.name) ? skip.name : [],
        ae = (typeof(skip.elem)=='string') ? skip.elem.toUpperCase().split(',')
            : isArray(skip.elem) ? skip.elem : [],
        at = (typeof(skip.type)=='string') ? skip.type.toLowerCase().split(',')
            : isArray(skip.type) ? skip.type : [];

    for ( var x=0, L=f.length; x<L; x++ ) {
        if ( !inArray(f[x].nodeName,ae) && !f[x].disabled && f[x].name
            && f[x].name!='' && !inArray(f[x].name.toLowerCase(),an) ) {
            switch ( f[x].nodeName ) {
                case 'INPUT':
                    if ( !inArray(f[x].type,at) ) {
                        switch ( f[x].type ) {
                            case 'text':
                            case 'hidden':
                            case 'password':
                                o.append(f[x].name, f[x].value);
                                break;
                            case 'file':
                                o.append(f[x].name, f[x].files);
                                break;
                            case 'radio':
                            case 'checkbox':
                                if ( f[x].checked ) {
                                    o.append(f[x].name, f[x].value);
                                    break;
                                }
                            break;
                        }
                    }
                    break;
                case 'TEXTAREA':
                    o.append(f[x].name, f[x].value);
                    break;
                case 'SELECT':
                    for (var z=0, J=f[x].length; z<J; z++) {
                        var Oz = f[x].options[z];
                        if ( Oz.selected ) {
                            o.append(f[x].name, Oz.value);
                        }
                    }
                    break;
            }
        }
    }
return o;
}

function htm$(surl, odata, elem){
    var htm = aja$({url:surl,data:odata}, {finish:function(a){
            if(elem && elem.nodeType){
                try {
                    elem.empty();
                } catch (e) {}
                elem.innerHTML=uesc(a);
            }
        }});
}

function post$(url, data, fn) {
    var pst = aja$( { url: url, data: data}, {finish: function(a){
            fn(a);
        } } );
return pst.status==200;
}


/**
 * 取得或设置cookie值
 */
function cookie(n, v, deps){/*name,value,{domain,expires,path,secure}*/
    if ( !n || typeof n!='string' || n.length==0 ) {
        return false;
    }

    if ( v===undefined ) {
        var co = me.cookie.replace(/\;/g, '&').jsonQs();
        return co.hasOwnProperty(n) ? co[n] : null;
    } else {
        var v = v===null ? '' : v +'',
            opt = ext({},deps);
        var expires = (typeof opt.expires=='number') ? ('; expires='+ new Date(opt.expires).toUTCString()) :
            (typeof opt.expires!='object' || typeof opt.expires.toUTCString!='function') ? '' :
            ('; expires='+ opt.expires.toUTCString());
        var path = (typeof opt.path=='string') ? '; path='+ (opt.path) : '';
        var domain = (typeof opt.domain=='string') ? '; domain='+ (opt.domain) : '';
        var secure = opt.secure ? '; secure' : '' ;
        me.cookie = (euc(n) +'='+ euc(v) + expires + path + domain + secure);
        return v;
    }
}

function pos(E){
    var T = E.offsetTop,
    L = E.offsetLeft,
    W = E.offsetWidth,
    H = E.offsetHeight,
    win = me.compatMode && me.compatMode!='BackCompat' ? me.documentElement : me.body;
    while ( E=E.offsetParent ) {
        L += E.offsetLeft;
        T += E.offsetTop;
    }
    var cw = win.clientWidth || self.innerWidth,
        ch = win.clientHeight || self.innerHeight,
        R = cw-L-W,
        B = ch-T-H,
        _R = L+W,
        _B = T+H;
return {'left':L, 'top':T, 'right':R, 'bottom':B, '_right':_R, '_bottom':_B, 'width':W, 'height':H, 'W':cw, 'H':ch};
}

function win$(){
    var win = me.compatMode && me.compatMode!='BackCompat' ? me.documentElement : me.body,
        w = $$.msie ? win.clientWidth : self.innerWidth,
        h = $$.msie ? win.clientHeight : self.innerHeight,
        r = w!=$$.width || h!=$$.height;
        $$.width = w;
        $$.height = h;
return {'width': w, 'height': h, resized: r};
}

function evt(ev){
    var e = window.event || ev;
    return {
        'el' : (e.target) ? e.target : e.srcElement,
        'key' : e.which || e.keyCode,
        'shift' : e.shiftKey,
        'ctrl' : e.ctrlKey,
        'alt' : e.altKey,
        'X' : e.clientX,
        'Y' : e.clientY,
        '_X' : e.screenX,
        '_Y' : e.screenY,
        'L' : (function(){
                var m = e.button;
            return $$.msie ? (m===1 || m===3 || m===5 || m===7) : m===0;})(),
        'R' : (function(){
                var m = e.button;
            return $$.msie ? (m===2 || m===3 || m===6 || m===7) : m===2;})(),
        'M' : (function(){
                var m = e.button;
            return $$.msie ? (m===4 || m===5 || m===6 || m===7) : m===1;})()
    };
}

/**
 * 设置或取得 元素的属性值
 */
function attr(e, a, v, f){
    if ( f===1 || f===0 ) {
        e.setAttribute(a, v, f);
    return e;
    } else if ( typeof v!='undefined' ) {
        e.setAttribute(a, v);
    return e;
    } else {
        return e.getAttribute(a);
    }
}

/**
 * 绑定事件
 */
function bind(o, evt, fn, cb){
    var aE = 'attachEvent',
        aEL = 'addEventListener';
    if ( !o[aE] && o[aEL] ) {
        return o[aEL](evt, fn, !!cb);
    }
return o[aE]('on'+ evt, fn);
}

function unbind(o, evt, fn, cb){
    var dE = 'detachEvent',
        rEL = 'removeEventListener';
    if (!o[dE] && o[rEL]) {
        return o[rEL](evt, fn, !!cb);
    }
return o[dE]('on'+ evt, fn);
}

/**
 * beta functions (to be renew or abandon)
 * ----
 */

function xo$(o){
    var y='';
    for(var x in o){
        if(typeof o[x]=='string'||typeof o[x]=='number'){
            y+=x +'='+ o[x] +'\n';
        }
    }
    return y;
}

function noevt(ev){
    var e=window.event||ev,
        pd='preventDefault',
        sp='stopPropagation';
    if(e[pd]){
        e[pd]();
    }else{
        e.returnValue=false;
    }
    if(e[sp]){
        e[sp]();
    }else{
        e.cancelBubble=true;
    }
}
function _(z){if(!z||typeof(z)!='string')return null;return me.getElementsByName(z);}
